package com.lanou.elh.sysmanage.item_manage.service.impl;

import com.lanou.elh.sysmanage.item_manage.entity.Item;
import com.lanou.elh.sysmanage.item_manage.mapper.ItemCatMapper;
import com.lanou.elh.sysmanage.item_manage.mapper.ItemMapper;
import com.lanou.elh.sysmanage.item_manage.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private ItemMapper itemMapper;
    @Autowired
    private ItemCatMapper itemCatMapper;

    @Override
    public Item getItemById(Long itemId) {
        Item item = new Item();
        item = itemMapper.selectById(itemId);

        String cname = itemCatMapper.selectCnameByCid(item.getCid());

        item.setCname(cname);
        return item;
    }

    @Override
    public List<Item> getItemList() {

        List<Item> itemList = itemMapper.selectItemList();
        for (Item item : itemList) {
            item.setCname(itemCatMapper.selectCnameByCid(item.getCid()));
        }

        return itemList;

    }

    @Override
    public Integer getItemCount() {

        return itemMapper.selectItemCount();
    }
}
